﻿Partial Public Class Formulario_web1
    Inherits System.Web.UI.Page
    Dim ocnEgresados As New CapaNegocio.Egresados()
    Dim ocnAlumnos As New CapaNegocio.Alumnos
    Dim ocnInstituciones As New CapaNegocio.Insituciones

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cargargrillaAlumnos()
        'cargargrillaInfoAcademica(Me.TextBoxDniAlumno1.Text)
    End Sub


    Function cargarListaInstituciones()
        Dim ds As New DataSet
        ds = ocnInstituciones.obtenerListaInstituciones()
        'AutoPostBack = true

        With Me.DropDownListInstitucion
            .DataSource = ds.Tables("ListaInstituciones").DefaultView
            .DataTextField = "nombreInstitucion"
            .DataValueField = "nombreInstitucion"
        End With
        Me.DropDownListInstitucion.DataBind()

        Return Me.DropDownListInstitucion

    End Function

    Private Sub DropDownListInstitucion_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownListInstitucion.Init
        cargarListaInstituciones()
    End Sub

    Function cargargrillaAlumnos()
        Dim ds As New DataSet

        ds = ocnAlumnos.obtenerAlumno()

        Me.GridViewAlumno.DataSource = ds.Tables(0)

        Me.GridViewAlumno.DataBind()
        Return Me.GridViewAlumno
    End Function

    Protected Sub ButtonGuardarAlumno_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGuardarAlumno.Click


        '  ocnAlumnos.dniAlumno = Me.TextBoxDniAlumno1.Text
        ' ocnAlumnos.nombre = Me.TextBoxNombre.Text
        'ocnAlumnos.domicilio = Me.TextBoxDomicilio.Text
        'ocnAlumnos.fechaNac = Me.CalendarFechaNac.Text
        'ocnAlumnos.estadoCivil = Me.TextBoxEstadoCivil.Text
        'ocnAlumnos.email = Me.TextBoxEmail.Text
        Try
            ocnAlumnos.insertarAlumno(Me.TextBoxDniAlumno1.Text, Me.TextBoxNombre.Text _
                            , CDate(Me.CalendarFechaNac.Text), Me.TextBoxEmail.Text _
                            , Me.TextBoxDomicilio.Text, Me.TextBoxEstadoCivil.Text)
            cargargrillaAlumnos()
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try

        '        If ocnAlumnos.insertarAlumno Then
        'MsgBox("alumno agregado")
        'cargargrilla()
        'Else
        'MsgBox("Error de ingreso")
        'End If
    End Sub

    Function cargargrillaInfoAcademica()
        Dim ds As New DataSet
        ds = ocnAlumnos.obtenerVistaAlumnoInfoAcademica()

        Me.GridViewAlumnoInfoAcademica.DataSource = ds.Tables(0)

        Me.GridViewAlumnoInfoAcademica.DataBind()
        Return Me.GridViewAlumnoInfoAcademica
    End Function

    Function cargargrillaInfoAcademica(ByVal dni As String)
        Dim ds As New DataSet
        ds = ocnAlumnos.obtenerVistaAlumnoInfoAcademica(dni)

        Me.GridViewAlumnoInfoAcademica.DataSource = ds.Tables(0)

        Me.GridViewAlumnoInfoAcademica.DataBind()
        Return Me.GridViewAlumnoInfoAcademica
    End Function

    Function cargargrillaInfoLaboral()
        Dim ds As New DataSet
        ds = ocnAlumnos.obtenerVistaAlumnoInfoLaboral()

        Me.GridViewAlumnoInfLaboral.DataSource = ds.Tables(0)

        Me.GridViewAlumnoInfLaboral.DataBind()
        Return Me.GridViewAlumnoInfLaboral
    End Function

    Function cargargrillaInfoLaboral(ByVal dni As String)
        Dim ds As New DataSet
        ds = ocnAlumnos.obtenerVistaAlumnoInfoLaboral(dni)

        Me.GridViewAlumnoInfLaboral.DataSource = ds.Tables(0)

        Me.GridViewAlumnoInfLaboral.DataBind()
        Return Me.GridViewAlumnoInfLaboral
    End Function



    Protected Sub ButtonGuardarInfoAcad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGuardarInfoAcad.Click
        Try
            ocnAlumnos.InsertarInfoAcademica(Me.TextBoxDniAlumno1.Text _
                                               , Me.DropDownListInstitucion.SelectedItem.Text _
                                               , Me.TextBoxTituloPosgrado.Text _
                                               , Me.CalendarAño.Text)
            cargargrillaInfoAcademica(Me.TextBoxDniAlumno1.Text)
            'cargarListaInstituciones()
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
 
    End Sub

    Protected Sub ButtonMostrarInfoAcad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonMostrarInfoAcad.Click
        Try
            cargargrillaInfoAcademica(Me.TextBoxDniAlumno1.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try

    End Sub

    Protected Sub ButtonGuardarInfoLaboral_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGuardarInfoLaboral.Click
        Try
            ocnAlumnos.InsertarInfoLaboral(Me.TextBoxDniAlumno1.Text, Me.TextBoxNombreEmpresa.Text _
                                                , Me.TextBoxPuesto.Text, Me.TextBoxFunciones.Text _
                                                , Me.TextBoxAntiguedad.Text)
            cargargrillaInfoLaboral(Me.TextBoxDniAlumno1.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try


    End Sub

    Protected Sub ButtonMostrarInfoLaboral_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonMostrarInfoLaboral.Click
        Try
            cargargrillaInfoLaboral(Me.TextBoxDniAlumno1.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub
End Class